apache 设置图片等静态文件的过期时间

        httpd.conf 中加入

1
2
3
4
5
6
7
8
ExpiresActive on
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"

        注释:

        Expires 语法如下:

1
ExpiresByType type/encoding "<base> [plus] {<num> <type>}*"

        其中是下列之一:

  • access
  • now (等价于’access’)
  • modification

        plus关键字是可选的。必须是整数[可以被atoi()接受的],是下列之一:

  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds

        参考: http://apache.chinahtml.com/mod/mod_expires.html